package com.dcdrake.testApp;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashSet;

import classes.Event;
import android.net.*;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;

public class CampusEventsActivity extends Activity {
	Event event;
	ArrayList<Event> list;
	public static final String PREFERENCE_FILENAME = "gamePrefs";
	//GregorianCalendar calendar;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        if(myApp.list != null){
        	LinearLayout ll = (LinearLayout) findViewById(R.id.linearLayout3);
        	
        	list = ((myApp) this.getApplication()).getList();
        	for(int i = 0; i <= list.size() - 1; i++){
        		int fontSize = 18;
        		Event nextEvent = list.get(i);
        		LayoutParams lp = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
            	TextView tv = new TextView(this);
            	tv.setTextSize(TypedValue.COMPLEX_UNIT_DIP, fontSize);
            	String eName = nextEvent.getName();
            	//Date eDate = nextEvent.getDate();
            	/*calendar = nextEvent.getCalendar();
            	int day = calendar.DAY_OF_MONTH;
            	int month = calendar.MONTH;
            	int year = calendar.YEAR;*/
            	int day = nextEvent.getDay();
            	int month = nextEvent.getMonth() + 1; //Correct for index of 0
            	int year = nextEvent.getYear();
            	String eLocation = nextEvent.getLocation();
            	tv.setText(eName + " " + month + "." + day + "." + year + " "+ eLocation);
            	ll.addView(tv);
        	}
        }
        else{
        	ArrayList<Event> list = new ArrayList<Event>();
        	((myApp) this.getApplication()).setList(list);
        }


        /*if(myApp.event != null){
        	event = ((myApp) this.getApplication()).getEvent();
        	LinearLayout ll = (LinearLayout) findViewById(R.id.linearLayout3);
        	LayoutParams lp = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
        	TextView tv = new TextView(this);
        	String eName = event.getName();
        	Date eDate = event.getDate();
        	String eLocation = event.getLocation();
        	tv.setText(eName + "     " + eLocation);
        	ll.addView(tv);
        }*/
        
        
    }
        public void onClick(View view){
        	switch (view.getId()){
        	
        	case R.id.add_event:
        		Intent addIntent = new Intent(view.getContext(), AddEventActivity.class);
            	startActivity(addIntent);
            	finish();
            	break;
            	
        	case R.id.sort_date:
        		//Add stuff here
        		break;
        		
        	case R.id.sort_loc:
        		//Add stuff here
        		break;
        	}
        }
        
        public void onDestroy(){
        	super.onDestroy();
        }
    
}